define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
	// 初始化表格参数配置
	Table.api.init({
		extend: {
			index_url: 'report/summary/index' + location.search,
			add_url: 'report/summary/add',
			del_url: 'report/summary/del',
			view_url: 'report/summary/view',
			table: 'report_summary',
		}
	});
	
    var Controller = {
        index: function () {
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
				search: false,
				searchFormVisible: true,
				showHeader: true,
				rowStyle:function(row,index){
					if(index%2 == 0)
					{
						return {css: {"background-color": "#c3ebd1"}};
					}
					else
					{
						return '';
					}
				},
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('序号'), sortable: true, searchable: false, formatter: function(value, row, index){
							var pageNumber = table.bootstrapTable('getOptions').pageNumber;
							var pageSize = table.bootstrapTable('getOptions').pageSize;
							return ++index + (pageNumber-1)*pageSize;
						}},
						{field: 'reportname', title: __('报表名称'), operate: 'LIKE'},
						{field: 'reporttime', title: __('预算时间（年）'), formatter: Table.api.formatter.datetime, addclass: 'datetimepicker', extend: "data-date-format='YYYY' data-use-current=true", datetimeFormat:'YYYY', sortable: true},
						//{field: 'createtime', title: __('生成时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'status', title: __('完成情况'), searchList:{0: __('未完成'), 1: __('已完成')}, formatter: Table.api.formatter.normal},				
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons:[
								{
									name: 'view',
									title: function(value, row){
										return value.reportname;
									},
									text:__('查看'),
									classname: 'btn btn-xs btn-primary btn-dialog',
									url: $.fn.bootstrapTable.defaults.extend.view_url,
									extend: 'data-area=\'["100%","100%"]\'',
								}
							],formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
		view: function(){
			var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: location.href,
                pk: 'id',
                sortName: 'id',
				commonSearch: false,
				showToggle: false,
				showColumns: false,
				rowStyle:function(row,index){
					if(index%2 == 0)
					{
						return {css: {"background-color": "#c3ebd1"}};
					}
					else
					{
						return '';
					}
				},
                columns: [
                    [
                        {field: 'id', title: __('序号'), sortable: true, rowspan: 2},
						{field: 'depart.name', title: __('单位'), rowspan: 2},
						{title: __('基本预算执行情况'), colspan: 4},
						{title: __('项目预算执行情况'), colspan: 5},
						
                    ],
					[
						{field: 'basicbudgetmoney', title: __('预算数')},
						{field: 'adjustbudgetamount', title: __('调整预算数')},
						{field: 'executeamount', title: __('执行数')},
						{title: __('执行率'), formatter:function(value, row, index){
							return (row.executeamount*100/row.adjustbudgetamount).toFixed(2)+'%';
						}},
						
						{field: 'projectbudgetmoney', title: __('预算数')},
						{title: __('调整预算数'), formatter:function(value, row, index){
							return row.alladjustbudgetamount-row.basicbudgetmoney;
						}},
						{title: __('执行数'), formatter:function(value, row, index){
							return row.allexecuteamount-row.executeamount;
						}},
						{title: __('执行率'), formatter:function(value, row, index){
							return ((row.allexecuteamount-row.executeamount)*100/(row.alladjustbudgetamount-row.basicbudgetmoney)).toFixed(2)+'%';
						}},
						{field: 'basicbudgetmoney', title: __('已录入一体化财政未审批数')},
					]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
		},
		add: function () {
			$(document).on('click','button[type="reset"]', function(){
				var index = parent.Layer.getFrameIndex(window.name);
				parent.Layer.close(index);
			});	
			
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});